package com.apex.sdk.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;

import com.apex.sdk.R;
import com.apex.sdk.api.DialCallback;
import com.apex.sdk.api.PreviewBitmapCallback;
import com.apex.sdk.model.WatchInfo;
import com.example.custom_dial.CustomDialCallback;
import com.example.custom_dial.CustomDiffTxtColorDialParam;
import com.example.custom_dial.CustomPointDialParam;
import com.example.custom_dial.NewRGBAPlatformDiffTxtUtils;
import com.example.custom_dial.NewRGBApointUtils;

public class HLDialUtils {
    final String TAG = this.getClass().getSimpleName();

    public void createTxtPreviewDial(@NonNull final Bitmap backBitmap, @NonNull final WatchInfo watchInfo, int txtColor, Context mContext, PreviewBitmapCallback previewBitmapCallback) {
        TxtPreviewTask previewTask = new TxtPreviewTask(backBitmap, watchInfo, txtColor, mContext, previewBitmapCallback);
        previewTask.execute();
    }

    public void createPointPreviewDial(@NonNull final Bitmap backBitmap, @NonNull final WatchInfo watchInfo, int style, Context mContext, PreviewBitmapCallback previewBitmapCallback) {
        PointPreviewTask previewTask = new PointPreviewTask(backBitmap, watchInfo, style, mContext, previewBitmapCallback);
        previewTask.execute();
    }

    public void createTxtDialBin(@NonNull final Bitmap backBitmap, @NonNull final WatchInfo watchInfo, int txtColor, Context mContext, @NonNull final Bitmap previewBitmap, final DialCallback dialCallback) {
        int startX = 0;
        int startY = 0;
        int weekX = 0;
        int weekY = 0;
        int dataX = 0;
        int screenWidth = watchInfo.lcd_full_w;
        int screenType = watchInfo.lcd_full_type;
        int screenHigh = watchInfo.lcd_full_h;
        int coreType = watchInfo.lcd_pixel_type;
        if (screenWidth == 240) {
            if (screenType == 1) {
                startX = 58;
                startY = 30;
                weekX = 80;
                weekY = 84;
                dataX = 133;
            } else {
                if (screenHigh == 296) {
                    startX = 47;
                    startY = 20;
                    weekX = 75;
                    weekY = 70;
                    dataX = 129;
                } else if (screenHigh == 280) {
                    startX = 47;
                    startY = 20;
                    weekX = 72;
                    weekY = 70;
                    dataX = 140;
                } else {
                    startX = 47;
                    startY = 20;
                    weekX = 60;
                    weekY = 70;
                    dataX = 146;
                }
            }
        } else if (screenWidth == 320) {
            startX = 82;
            startY = 35;
            weekX = 95;
            weekY = 110;
            dataX = 150;

        } else if (screenWidth == 340) {
            startX = 95;
            startY = 35;
            weekX = 98;
            weekY = 110;
            dataX = 167;
        } else if (screenWidth == 356) {
            startX = 88;
            startY = 20;
            weekX = 75;
            weekY = 95;
            dataX = 155;
        } else if (screenWidth == 360) {
            if (screenType == 1) {
                if (!TextUtils.isEmpty(watchInfo.watchType)) {
                    if (watchInfo.watchType.equalsIgnoreCase("APEX_G16")) {
                        startX = 90;
                        startY = 20;
                        weekX = 125;
                        weekY = 95;
                        dataX = 125;
                    } else if (watchInfo.watchType.contains("Solar Neo")) {
                        startX = 90;
                        startY = 20;
                        weekX = 120;
                        weekY = 95;
                        dataX = 123;
                    } else {
                        startX = 90;
                        startY = 20;
                        weekX = 100;
                        weekY = 95;
                        dataX = 140;
                    }
                }
            } else {
                startX = 90;
                startY = 20;
                weekX = 135;
                weekY = 95;
                dataX = 105;
            }
        } else if (screenWidth == 368) {
            startX = 98;
            startY = 20;
            weekX = 98;
            weekY = 95;
            dataX = 163;
        } else if (screenWidth == 390) {
            Log.e(TAG, "走了这里");
            startX = 96;
            startY = 40;
            weekX = 95;
            weekY = 140;
            if (coreType == 2) {
                if (screenHigh == 450) {
                    dataX = 190;
                } else {
                    dataX = 200;
                }
            } else {
                dataX = 220;
            }
        } else if (screenWidth == 410) {
            startX = 105;
            startY = 20;
            weekX = 117;
            weekY = 140;
            dataX = 193;
        } else if (screenWidth == 412) {
            startX = 107;
            startY = 20;
            weekX = 118;
            weekY = 140;
            dataX = 193;
        } else if (screenWidth == 466) {
            startX = 127;
            startY = 30;
            weekX = 165;
            weekY = 140;
            dataX = 235;
        }
        if (startX != 0) {
            CustomDiffTxtColorDialParam customDiffTxtColorDialParam = new CustomDiffTxtColorDialParam();
            customDiffTxtColorDialParam.setDateX(dataX);
            customDiffTxtColorDialParam.setWy(weekY);
            customDiffTxtColorDialParam.setWx(weekX);
            customDiffTxtColorDialParam.setStartY(startY);
            customDiffTxtColorDialParam.setStartX(startX);
            customDiffTxtColorDialParam.setTxtColor(txtColor);
            customDiffTxtColorDialParam.setScreenType(screenType);
            customDiffTxtColorDialParam.setCornerRadius(watchInfo.lcd_preview_radius);
            customDiffTxtColorDialParam.setScreenWidth(screenWidth);
            customDiffTxtColorDialParam.setScreenHigh(screenHigh);
            customDiffTxtColorDialParam.setpWidth(watchInfo.lcd_preview_w);
            customDiffTxtColorDialParam.setpHigh(watchInfo.lcd_preview_h);
            customDiffTxtColorDialParam.setBackBitmap(backBitmap);
            customDiffTxtColorDialParam.setPreviewBitmap(previewBitmap);
            final NewRGBAPlatformDiffTxtUtils rgbaPlatformDiffTxtUtils = new NewRGBAPlatformDiffTxtUtils(mContext.getApplicationContext(), watchInfo.lcd_pixel_type);
            rgbaPlatformDiffTxtUtils.showData(true);
            rgbaPlatformDiffTxtUtils.produceDialBin(customDiffTxtColorDialParam, new CustomDialCallback() {
                @Override
                public void dialPath(final String s) {
                    rgbaPlatformDiffTxtUtils.destroy();
                    if (dialCallback != null) {
                        dialCallback.dialFile(s);
                    }


                }
            });
        } else {
            if (dialCallback != null) {
                dialCallback.dialFile(null);
            }
        }


    }

    public void createPointDialBin(@NonNull final Bitmap backBitmap, @NonNull final WatchInfo watchInfo, Context mContext, int style, @NonNull final Bitmap previewBitmap, final DialCallback dialCallback) {

        int screenWidth = watchInfo.lcd_full_w;
        int screenHigh = watchInfo.lcd_full_h;
        int screenType = watchInfo.lcd_full_type;
        int coreType = watchInfo.lcd_pixel_type;

        CustomPointDialParam customPointDialParam = new CustomPointDialParam();
        customPointDialParam.setBackBitmap(backBitmap);
        customPointDialParam.setCornerRadius(watchInfo.lcd_preview_radius);
        customPointDialParam.setPreviewHigh(watchInfo.lcd_preview_h);
        customPointDialParam.setPreviewWidth(watchInfo.lcd_preview_w);
        customPointDialParam.setScreenHigh(screenHigh);
        customPointDialParam.setScreenType(screenType);
        customPointDialParam.setScreenWidth(screenWidth);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = false;
        Bitmap tBit = null, hourBit = null, minuteBit = null, secondBit = null, frameBit = null;
        if (style == 0) {
            if (screenWidth == 240) {
                if (screenHigh == 240) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else if (screenHigh == 296) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240, options);
                    customPointDialParam.sethTop(90);
                    customPointDialParam.setmTop(47);
                    customPointDialParam.setsTop(35);
                } else {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }

            } else if (screenWidth == 320) {
                if (screenHigh == 386) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_320, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_320, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_320, options);
                    customPointDialParam.sethTop(118);
                    customPointDialParam.setmTop(64);
                    customPointDialParam.setsTop(45);
                } else {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_320, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_320, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_320, options);
                    customPointDialParam.sethTop(118);
                    customPointDialParam.setmTop(64);
                    customPointDialParam.setsTop(45);
                }
            } else if (screenWidth == 340) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_320, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_320, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_320, options);
                customPointDialParam.sethTop(92);
                customPointDialParam.setmTop(42);
                customPointDialParam.setsTop(23);
            } else if (screenWidth == 356) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                customPointDialParam.sethTop(104);
                customPointDialParam.setmTop(64);
                customPointDialParam.setsTop(36);
            } else if (screenWidth == 360) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                customPointDialParam.sethTop(84);
                customPointDialParam.setmTop(44);
                customPointDialParam.setsTop(16);
            } else if (screenWidth == 368) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                customPointDialParam.sethTop(128);
                customPointDialParam.setmTop(88);
                customPointDialParam.setsTop(60);
            } else if (screenWidth == 390) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                if (coreType != 2) {
                    customPointDialParam.sethTop(100);
                    customPointDialParam.setmTop(60);
                    customPointDialParam.setsTop(31);
                } else {
                    customPointDialParam.sethTop(130);
                    customPointDialParam.setmTop(89);
                    customPointDialParam.setsTop(62);
                }
            } else if (screenWidth == 410) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                customPointDialParam.sethTop(155);
                customPointDialParam.setmTop(115);
                customPointDialParam.setsTop(87);
            } else if (screenWidth == 412) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_356, options);
                customPointDialParam.sethTop(156);
                customPointDialParam.setmTop(116);
                customPointDialParam.setsTop(88);
            } else if (screenWidth == 466) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }

        } else if (style == 1) {
            if (screenWidth == 240) {
                if (screenHigh == 240) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else if (screenHigh == 296) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240, options);
                    customPointDialParam.sethTop(90);
                    customPointDialParam.setmTop(47);
                    customPointDialParam.setsTop(35);
                } else {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }
            } else if (screenWidth == 320) {
                if (screenHigh == 386) {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_320, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_320, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_320, options);
                    customPointDialParam.sethTop(118);
                    customPointDialParam.setmTop(64);
                    customPointDialParam.setsTop(45);
                } else {
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_320, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_320, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_320, options);
                    customPointDialParam.sethTop(118);
                    customPointDialParam.setmTop(64);
                    customPointDialParam.setsTop(45);
                }
            } else if (screenWidth == 340) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_320, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_320, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_320, options);
                customPointDialParam.sethTop(92);
                customPointDialParam.setmTop(42);
                customPointDialParam.setsTop(23);
            } else if (screenWidth == 356) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                customPointDialParam.sethTop(104);
                customPointDialParam.setmTop(64);
                customPointDialParam.setsTop(36);
            } else if (screenWidth == 360) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                customPointDialParam.sethTop(84);
                customPointDialParam.setmTop(44);
                customPointDialParam.setsTop(16);
            } else if (screenWidth == 368) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                customPointDialParam.sethTop(128);
                customPointDialParam.setmTop(88);
                customPointDialParam.setsTop(60);
            } else if (screenWidth == 390) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                if (coreType != 2) {
                    customPointDialParam.sethTop(100);
                    customPointDialParam.setmTop(60);
                    customPointDialParam.setsTop(31);
                } else {
                    customPointDialParam.sethTop(130);
                    customPointDialParam.setmTop(89);
                    customPointDialParam.setsTop(62);
                }
            } else if (screenWidth == 410) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                customPointDialParam.sethTop(155);
                customPointDialParam.setmTop(115);
                customPointDialParam.setsTop(87);
            } else if (screenWidth == 412) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_356, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_356, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_356, options);
                customPointDialParam.sethTop(156);
                customPointDialParam.setmTop(116);
                customPointDialParam.setsTop(88);
            } else if (screenWidth == 466) {
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }
        } else if (style == 2) {
            if (screenWidth == 240) {
                if (screenHigh == 240) {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_black_240_circle, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_black_240_280, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }
            } else if (screenWidth == 466) {
                frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_black_466_circle, options);
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }
        } else if (style == 3) {
            if (screenWidth == 240) {
                if (watchInfo.lcd_full_type == 1) {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_white_240_circle, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_white_240_280, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }
            } else if (screenWidth == 466) {
                frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_txt_white_466_circle, options);
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }
        } else if (style == 4) {
            if (screenWidth == 240) {
                if (watchInfo.lcd_full_type == 1) {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_black_240_circle, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_black_240_280, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }
            } else if (screenWidth == 466) {
                frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_black_466_circle, options);
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_black_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_black_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_black_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }
        } else if (style == 5) {
            if (screenWidth == 240) {
                if (watchInfo.lcd_full_type == 1) {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_white_240_circle, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240_circle, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240_circle, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240_circle, options);
                    customPointDialParam.sethTop(65);
                    customPointDialParam.setmTop(23);
                    customPointDialParam.setsTop(9);
                } else {
                    frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_white_240_280, options);
                    hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_240, options);
                    minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_240, options);
                    secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_240, options);
                    customPointDialParam.sethTop(83);
                    customPointDialParam.setmTop(40);
                    customPointDialParam.setsTop(27);
                }
            } else if (screenWidth == 466) {
                frameBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.frame_point_kedu_white_466_circle, options);
                hourBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_hour_white_466, options);
                minuteBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_minute_white_466, options);
                secondBit = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.point_second_white_466, options);
                customPointDialParam.sethTop(126);
                customPointDialParam.setmTop(41);
                customPointDialParam.setsTop(17);
            }
        }
        if (hourBit != null) {
            customPointDialParam.setHourBitmap(hourBit);
            customPointDialParam.setSecondBitmap(secondBit);
            customPointDialParam.setMinuteBitmap(minuteBit);
            customPointDialParam.setPreviewBitmap(previewBitmap);
            customPointDialParam.setFrameBitmap(frameBit);
            final NewRGBApointUtils rgbaPointUtils = new NewRGBApointUtils(mContext.getApplicationContext(), watchInfo.lcd_pixel_type);
            rgbaPointUtils.produceDialBin(customPointDialParam, new CustomDialCallback() {
                @Override
                public void dialPath(final String s) {
                    rgbaPointUtils.destroy();
                    if (dialCallback != null) {
                        dialCallback.dialFile(s);
                    }
                }
            });
        } else {
            if (dialCallback != null) {
                dialCallback.dialFile(null);
            }
        }

    }

    class TxtPreviewTask extends AsyncTask<Void, Void, Bitmap> {
        Bitmap backBitmap;
        WatchInfo watchInfo;
        int txtColor;
        Context mContext;
        PreviewBitmapCallback previewBitmapCallback;


        public TxtPreviewTask(Bitmap backBitmap, WatchInfo watchInfo, int txtColor, Context mContext, PreviewBitmapCallback previewBitmapCallback) {
            this.backBitmap = backBitmap;
            this.watchInfo = watchInfo;
            this.txtColor = txtColor;
            this.mContext = mContext;
            this.previewBitmapCallback = previewBitmapCallback;

        }

        @Override
        protected Bitmap doInBackground(Void... integers) {
            //将背景图进行缩放
            if (backBitmap != null) {
                int bWidth = backBitmap.getWidth();
                int bHigh = backBitmap.getHeight();
                if (bWidth < watchInfo.lcd_full_w || bHigh < watchInfo.lcd_full_h) {
                    float wScale = watchInfo.lcd_full_w * 1.0f / bWidth;
                    float hScale = watchInfo.lcd_full_h * 1.0f / bHigh;
                    float mScale = Math.max(wScale, hScale);
                    Matrix matrix = new Matrix();
                    matrix.setScale(mScale, mScale);
                    backBitmap = Bitmap.createBitmap(backBitmap, 0, 0, backBitmap.getWidth(), backBitmap.getHeight(), matrix, false);
                    Log.e(TAG, "缩放之后图片的大小,宽:" + backBitmap.getWidth() + ",高:" + backBitmap.getHeight());
                }
            }
            int startX = 0;
            int startY = 0;
            int weekX = 0;
            int weekY = 0;
            int dataX = 0;
            int screenWidth = watchInfo.lcd_full_w;
            int screenType = watchInfo.lcd_full_type;
            int screenHigh = watchInfo.lcd_full_h;
            if (screenWidth == 240) {
                if (screenType == 1) {
                    startX = 58;
                    startY = 30;
                    weekX = 80;
                    weekY = 84;
                    dataX = 133;
                } else {
                    if (screenHigh == 296) {
                        startX = 47;
                        startY = 20;
                        weekX = 95;
                        weekY = 70;
                        dataX = 121;
                    } else if (screenHigh == 280) {
                        startX = 47;
                        startY = 20;
                        weekX = 95;
                        weekY = 70;
                        dataX = 121;
                    } else if (screenHigh == 240) {
                        startX = 47;
                        startY = 20;
                        weekX = 95;
                        weekY = 70;
                        dataX = 121;
                    } else {
                        startX = 47;
                        startY = 20;
                        weekX = 60;
                        weekY = 70;
                        dataX = 146;
                    }
                }
            } else if (screenWidth == 320) {
                startX = 85;
                startY = 35;
                weekX = 115;
                weekY = 110;
                dataX = 165;
            } else if (screenWidth == 340) {
                startX = 95;
                startY = 35;
                weekX = 122;
                weekY = 110;
                dataX = 173;
            } else if (screenWidth == 356) {
                startX = 88;
                startY = 20;
                weekX = 75;
                weekY = 95;
                dataX = 155;
            } else if (screenWidth == 360) {
                startX = 90;
                startY = 20;
                weekX = 105;
                weekY = 95;
                dataX = 190;
            } else if (screenWidth == 368) {
                startX = 98;
                startY = 20;
                weekX = 112;
                weekY = 95;
                dataX = 193;
            } else if (screenWidth == 390) {
                startX = 95;
                startY = 20;
                weekX = 95;
                weekY = 140;
                dataX = 220;
            } else if (screenWidth == 410 || screenWidth == 412) {
                startX = 106;
                startY = 20;
                weekX = 120;
                weekY = 140;
                dataX = 220;
            } else if (screenWidth == 466) {
                startX = 127;
                startY = 30;
                weekX = 155;
                weekY = 140;
                dataX = 245;
            }
            if (startX != 0) {
                NewRGBAPlatformDiffTxtUtils rgbaPlatformDiffTxtUtils = new NewRGBAPlatformDiffTxtUtils(mContext.getApplicationContext(), watchInfo.lcd_pixel_type);
                rgbaPlatformDiffTxtUtils.showData(true);

                Bitmap bitmap = rgbaPlatformDiffTxtUtils.produceDialThumbnail(backBitmap, screenWidth, screenHigh, watchInfo.lcd_preview_radius,
                        screenType, startX, startY, weekX, weekY, txtColor, dataX, watchInfo.lcd_preview_w, watchInfo.lcd_preview_h);
                Log.e(TAG, "开始坐标" + startX + "," + startY + ",日期时间坐标:" + weekX + "," + weekY + "," + dataX + " bitmap " + (bitmap == null));
                rgbaPlatformDiffTxtUtils.destroy();

                return bitmap;
            } else {

                return null;
            }

        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
            mContext = null;
            if (previewBitmapCallback != null) {
                previewBitmapCallback.getPreview(bitmap);
            }

        }
    }

    class PointPreviewTask extends AsyncTask<Void, Void, Bitmap> {
        Bitmap backBitmap;
        WatchInfo watchInfo;
        int pointStyle;
        Context mContext;
        PreviewBitmapCallback previewBitmapCallback;

        public PointPreviewTask(Bitmap backBitmap, WatchInfo watchInfo, int pointStyle, Context mContext, PreviewBitmapCallback previewBitmapCallback) {
            this.backBitmap = backBitmap;
            this.watchInfo = watchInfo;
            this.pointStyle = pointStyle;
            this.mContext = mContext;
            this.previewBitmapCallback = previewBitmapCallback;
        }

        @Override
        protected Bitmap doInBackground(Void... integers) {
            //将背景图进行缩放
            if (backBitmap != null) {
                int bWidth = backBitmap.getWidth();
                int bHigh = backBitmap.getHeight();
                if (bWidth < watchInfo.lcd_full_w || bHigh < watchInfo.lcd_full_h) {
                    float wScale = watchInfo.lcd_full_w * 1.0f / bWidth;
                    float hScale = watchInfo.lcd_full_h * 1.0f / bHigh;
                    float mScale = Math.max(wScale, hScale);
                    Matrix matrix = new Matrix();
                    matrix.setScale(mScale, mScale);
                    backBitmap = Bitmap.createBitmap(backBitmap, 0, 0, backBitmap.getWidth(), backBitmap.getHeight(), matrix, false);
                    Log.e(TAG, "缩放之后图片的大小,宽:" + backBitmap.getWidth() + ",高:" + backBitmap.getHeight());
                }
            }
            int screenWidth = watchInfo.lcd_full_w;
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;
            Bitmap bBitMap = null;
            if (pointStyle == 0) {
                if (screenWidth == 240) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_240, options);
                } else if (screenWidth == 320) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 340) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 356 || screenWidth == 360) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 368) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_466, options);
                } else if (screenWidth == 390) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 410) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                } else if (screenWidth == 412) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_point_356, options);
                }


            } else if (pointStyle == 1) {
                if (screenWidth == 240) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_240, options);

                } else if (screenWidth == 320) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 340) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 356 || screenWidth == 360) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 368) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_466, options);
                } else if (screenWidth == 390) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 410) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                } else if (screenWidth == 412) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_point_356, options);
                }

            } else if (pointStyle == 2) {
                if (screenWidth == 240) {
                    if (watchInfo.lcd_full_type != 1) {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_txt_point_240, options);
                    } else {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_txt_point_240_circle, options);
                    }

                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_txt_point_466_circle, options);
                }
            } else if (pointStyle == 3) {
                if (screenWidth == 240) {
                    if (watchInfo.lcd_full_type != 1) {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_txt_point_240, options);
                    } else {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_txt_point_240_circle, options);
                    }

                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_txt_point_466_circle, options);
                }
            } else if (pointStyle == 4) {
                if (screenWidth == 240) {
                    if (watchInfo.lcd_full_type != 1) {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_kedu_point_240, options);
                    } else {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_kedu_point_240_circle, options);
                    }

                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_black_kedu_point_466_circle, options);
                }
            } else if (pointStyle == 5) {
                if (screenWidth == 240) {
                    if (watchInfo.lcd_full_type != 1) {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_kedu_point_240, options);
                    } else {
                        bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_kedu_point_240_circle, options);
                    }

                } else if (screenWidth == 466) {
                    bBitMap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.thum_white_kedu_point_466_circle, options);
                }
            }
            if (bBitMap != null) {
                NewRGBApointUtils rgbaPointUtils = new NewRGBApointUtils(mContext.getApplicationContext(), watchInfo.lcd_pixel_type);
                Bitmap previewBitmap = rgbaPointUtils.produceDialThumbnail(backBitmap, watchInfo.lcd_preview_w, watchInfo.lcd_preview_h, watchInfo.lcd_preview_radius, watchInfo.lcd_full_type, bBitMap);
                rgbaPointUtils.destroy();
                return previewBitmap;
            }
            return null;

        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
            mContext = null;
            if (previewBitmapCallback != null) {
                previewBitmapCallback.getPreview(bitmap);
            }

        }
    }
}
